package cn.bsb.controller.rece;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import cn.bsb.pojo.DevUser;
import cn.bsb.service.rece.ArticleService;
import cn.bsb.service.rece.DevUserService;
import cn.bsb.tools.Constants;

@Controller
public class DevUserControll {
	@Resource(name="DevUserService")
	private DevUserService devUserService;
	@Resource(name="ArticleService")
	  private ArticleService articleService;
	@RequestMapping(value="/sys/modifyUser",method=RequestMethod.GET)
	public String modifyUser(Model model,HttpSession session,
			@RequestParam(name="flag",required=false)String flag) {
		long id=((DevUser)session.getAttribute("loginUser")).getId();
		int id2=(int)id;
		int count = articleService.getCount(id2);
		if(flag!=null&&flag.equals("ok")) {
			DevUser user=devUserService.getUser(id2);
			session.setAttribute("loginUser", user);
		}
	
		model.addAttribute("count",count);
		model.addAttribute("flag",flag);
		return "rece/usermodify";
	}
	@RequestMapping(value="/sys/modifyUser",method=RequestMethod.POST)
	public String modify(Model model,HttpSession session,DevUser user) {
		String flag=null;
		if(devUserService.updateUser(user)) {
			flag="ok";
		}else {
			flag="no";
		}
		return "redirect:/sys/modifyUser?flag="+flag;
	}
	
}
